<template>
  <el-button style="width: 100%;" text @click="copyToClipboard(props.text)">
    {{ props.text }}
  </el-button>
</template>

<script lang="ts" setup>
import { ElNotification } from "element-plus";

const props = defineProps({
  text: {
    type: String,
    default: "",
  },
});

const copyToClipboard = () => {
  navigator.clipboard
    .writeText(props.text)
    .then(() => {
      ElNotification({
        type: "warning",
        title: "提示",
        message: `复制成功! ${props.text}`,
      });
    })
    .catch((error) => {
      console.error("复制失败: ", error);
    });
};
</script>
